﻿using BootstrapBlazorApp.Shared.Shared;
using Microsoft.AspNetCore.Components.Authorization;
using Microsoft.Extensions.Configuration;
using Microsoft.Extensions.DependencyInjection;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace BootstrapBlazorApp.Shared.Services
{
    public static class ServicesEx
    {
        public static void Create(this IServiceCollection services, ConfigurationManager api)
        {
            services.AddAuthorizationCore();
            services.AddScoped<JwtAuthenticationStateProvider>();
            services.AddScoped<AuthenticationStateProvider, JwtAuthenticationStateProvider>();
            services.AddScoped<ITokenInterceptor, TokenInterceptor>();

            #region 注册webapi请求代理
            services.AddHttpApi<ISysApi>();
            services.AddWebApiClient().ConfigureHttpApi(x =>
            {
                //x.GlobalFilters.Add(new LogFilter());
                x.HttpHost = new Uri(api["ApiBase"]);
                x.Properties.Add("Cache-Control", "no-cache");
                x.Properties.Add("User-Agent", "Mozilla/4.0 (compatible; MSIE 6.0; Windows NT 5.2; SV1; .NET CLR 1.1.4322; .NET CLR 2.0.50727)");
            });

            //实例化静态类 
            Application.Instance = services.BuildServiceProvider();
            #endregion
            

        }
    }
}
